package com.mccken.demo.io.service;

import java.util.List;
import java.util.UUID;

import com.mccken.demo.io.pojo.Item;
import com.mccken.demo.io.pojo.Order;

import lombok.extern.slf4j.Slf4j;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2022-04-30 22:20
 **/
@Slf4j
public class OrderServiceImpl implements OrderService{
	@Override
	public Order submitOrder(Long userId, List<Item> itemList) {

		Long count = 0L;
		for (Item item : itemList) {
			count += item.getPrice();
		}
		
		return Order.builder()
				.orderId(UUID.randomUUID().toString())
				.date(System.currentTimeMillis())
				.itemCount(itemList.size())
				.userId(userId)
				.totalPrice(count)
				.build();
	}
}
